home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / gfx / misc / VividCompare.lha / AmigaMandel.c < prev    next >
C/C++ Source or Header  |  1993-07-23  |  12KB  |  412 lines

  1. /*
  2.  * Mandel2.c - Vivid 24 to Amiga speed comparison
  3.  *
  4.  */
  5.  
  6. #define CONFIG_VAL 0xefa00434
  7. #define MODE 6  /* 800 x 600 */
  8. #define HRES 800
  9. #define VRES 600
  10. #define SRAM_FILE "MANDEL.ABS"
  11.  
  12. /* Uncomment this line to have the Amiga render to the Vivid rather */
  13. /*  than its own screen.                                            */
  14. //#define AMIGA2VIVID
  15.  
  16. #define FAST
  17.  
  18. #include <exec/types.h>
  19. #include <exec/memory.h>
  20. #include <proto/exec.h>
  21. #include <proto/dos.h>
  22. #include <proto/intuition.h>
  23. #include <proto/graphics.h>
  24.  
  25. #include <time.h>
  26. #include <stdio.h>
  27.  
  28. #include <sage/sage_proto.h>
  29. #include <sage/sage_pragma.h>
  30.  
  31. #include <sage/tms340/gsptypes.h>
  32. #include <sage/tms340/gspreg.h>
  33. #include <sage/tms340/tms340.h>
  34. #include <sage/vivid/iodata.h>
  35.  
  36. #include <sage/tms340/colors.h>
  37.  
  38. // tms340 library
  39. #include <sage/tms340/tms340_proto.h>
  40. #include <sage/tms340/tms340_pragma.h>
  41.  
  42. // macros
  43. #include <sage/tms340/tms340_defines.h>
  44.  
  45. #include "/extSRAM/extSRAMpragma.h"
  46. #include "/extSRAM/extSRAMprotos.h"
  47. #include "/extSRAM/extSRAM.h"
  48.  
  49. struct Library *SAGEBase;
  50. struct Library *TMS340Base;
  51. struct Library *extSRAMBase;
  52.  
  53. struct iodata *TMS340io;
  54. struct iodata *extio;
  55. SAGEList *sagelist;
  56. SAGEList *sl;
  57. SAGEInfo sageinfo;
  58.  
  59. CONFIG config;
  60.  
  61. extern void ReverseBytes(ULONG *, int);
  62. extern void LoadSRAMCode(LONG, ULONG *, LONG);
  63.  
  64. struct Screen *Screen;
  65. struct Window *Window;
  66.  
  67.  
  68. void ComputeFractal(void)
  69. {
  70.   UWORD Row, Column;
  71.   float DeltaI = 2.0 / (float)VRES;
  72.   float DeltaR = 3.0 / (float)HRES;
  73.   float AR, AR2, AI, AI2;
  74.   float ConstI, ConstR;
  75.  
  76. #ifdef AMIGA2VIVID
  77.   ULONG Color;
  78.   ULONG *PixelData;
  79.   ULONG *screenAddr = (ULONG *)TMS340io->baddr->mem_base;
  80.   clear_frame_buffer(0x00);
  81.   PixelData = AllocMem(HRES * sizeof(ULONG), MEMF_ANY);
  82. #else
  83. #ifdef FAST
  84.   UBYTE Color;
  85.   struct RastPort *rastPort = &Screen->RastPort;
  86.   UBYTE *PixelData;
  87.   struct RastPort tempRastPort;
  88.   struct BitMap tempBitMap;
  89.   int plane;
  90.   PixelData = AllocMem((HRES * sizeof(UBYTE)) + 15, MEMF_ANY);
  91. //  InitRastPort(&tempRastPort);
  92. tempRastPort = *rastPort;
  93.   tempRastPort.Layer = NULL;
  94.   InitBitMap(&tempBitMap, 8, HRES, VRES);
  95.   tempRastPort.BitMap = &tempBitMap;
  96.   for(plane = 0; plane < 8; plane++)
  97.   {
  98.     tempBitMap.Planes[plane] = AllocMem((((HRES + 15) >> 4) << 1), MEMF_CHIP | MEMF_CLEAR);
  99.   }
  100. #else
  101.   UBYTE Color;
  102.   struct RastPort *rastPort = &Screen->RastPort;
  103. #endif
  104. #endif
  105.  
  106.   for(Row = 0; Row < VRES; Row++)
  107.   {
  108.     ConstI = (DeltaI * (float)Row) - 1;
  109.     ConstR = -2;
  110.     for(Column = 0; Column < HRES; Column++)
  111.     {
  112.       AR = AI = AR2 = AI2 = 0;
  113.       for(Color = 128; Color > 0; Color--)
  114.       {
  115.         AI = (AR * AI * 2) + ConstI;
  116.         AR = AR2 - AI2 + ConstR;
  117.         AR2 = AR * AR;
  118.         AI2 = AI * AI;
  119.         if((AR2 + AI2) > 4)
  120.           break;
  121.       }
  122. #ifdef AMIGA2VIVID
  123.       PixelData[Column] = Color;
  124. #else 
  125. #ifdef FAST
  126.       PixelData[Column] = Color;
  127. #else     
  128.       SetAPen(rastPort, Color);
  129.       WritePixel(rastPort, Column, Row);
  130. #endif
  131. #endif
  132.       ConstR += DeltaR;
  133.     }
  134. #ifdef AMIGA2VIVID
  135.     CopyMemQuick((APTR)PixelData, (APTR)(screenAddr + (Row << 10)), HRES << 2);
  136. #endif
  137. #ifdef FAST
  138.     WritePixelLine8(&Screen->RastPort, 0, Row, HRES, PixelData, &tempRastPort);
  139. #endif
  140.   }
  141. #ifdef AMIGA2VIVID
  142.   FreeMem(PixelData, HRES * sizeof(ULONG));
  143. #endif
  144. #ifdef FAST
  145.   FreeMem(PixelData, (HRES * sizeof(UBYTE)) + 15);
  146.   for(plane = 0; plane < 8; plane++)
  147.   {
  148.     FreeMem(tempBitMap.Planes[plane], (((HRES + 15) >> 4) << 1));
  149.   }
  150. #endif
  151. }
  152.  
  153.  
  154. void main(void)
  155. {
  156.   long data, prog;
  157.   long *dataAddr, *progAddr;
  158.   int SAGEAlive = 0;
  159.   struct FileInfoBlock fib;
  160.   BPTR handle;
  161.   unsigned int clock1[2], clock2[2], clock3[2];
  162.   unsigned int amigaTime, vividTime;
  163.   
  164.   printf("Vivid 24, Mandelbrot calculation comparison program.\n");
  165.   printf("\tCopyright ©1993 - Digital Micronics, Inc.\n\n");
  166.   printf("\tThis program is being used to compare rendering speed and\n");
  167.   printf("\tprocessing power of the Amiga to the Vivid 24 rendering\n");
  168.   printf("\tengine.  It is released as freely redistributalbe to show we\n");
  169.   printf("\tare not using \"smoke and mirrors\" when we compare the\n");
  170.   printf("\tVivid 24 to your Amiga.  The Mandelbrot routines are not\n");
  171.   printf("\tas highly optimized as some code, but since the Vivid 24\n");
  172.   printf("\tis running the identical code (see included source), it is\n");
  173.   printf("\ta fair comparison of RELATIVE performance.  This code will\n");
  174.   printf("\trun with our without a Vivid 24 installed.  Without the\n");
  175.   printf("\tboard, it will test your Amiga and display the results as\n");
  176.   printf("\tcompared to the various configuration of the Vivid 24.  With\n");
  177.   printf("\ta Vivid 24 card installed, you will be given the times\n");
  178.   printf("\tyourself so you can make your own comparison.\n\n");
  179.   
  180.   printf("Attempting to load Vivid 24 environment.\n");
  181.   if(SAGEBase = OpenLibrary("sage.library", 0))
  182.   {
  183.     if(!GetSAGEList(&sagelist, "TMS340"))
  184.     {
  185.       if(!OpenSAGE(&sageinfo, 0, sagelist->LibName, 1, 0, 0))
  186.       {
  187.         TMS340Base = sageinfo.LibBase;
  188.         TMS340io = sageinfo.iodata;
  189.         if(!open_gsp_library(sageinfo.iodata, &extio, "extSRAM", 0, 0))
  190.         {
  191.           extSRAMBase = get_libbase(extio);
  192.           get_config(&config);
  193.           if(config.sys_flags & 0x0000000f)
  194.           {
  195.             if(handle = Open(SRAM_FILE, MODE_OLDFILE))
  196.             {
  197.               ExamineFH(handle, &fib);
  198.               if(prog = gsp_malloc(fib.fib_Size + 8))
  199.               {
  200.                 prog += 64;
  201.                 if(data = gsp_malloc(256 + 8))
  202.                 {
  203.                   data += 64;
  204.                   progAddr = (ULONG *)(((prog - 0xf0000000) >> 3) +
  205.                                                    extio->baddr->mem_base);
  206.                   dataAddr = (ULONG *)(((data - 0xf0000000) >> 3) +
  207.                                                    extio->baddr->mem_base);
  208.                   if(Read(handle, progAddr, fib.fib_Size) == fib.fib_Size)
  209.                   {
  210.                     SAGEAlive = ~0;
  211.                     ReverseBytes(progAddr, fib.fib_Size);
  212.                     set_config(MODE, 1);
  213.                     set_coloring_mode(INDEXCOLOR);
  214.                     clear_frame_buffer(0x00);
  215.                     Init082Int(extio, TMS340Base);
  216.                     *dataAddr = *(dataAddr + 1) = CONFIG_VAL;
  217.                     if(config.sys_flags & 0x00000001)
  218.                     {
  219.                       Abort082(extio, TMS340Base, 0);
  220.                       Set082Regs(extio, TMS340Base, 0, CR_CONFIG, data, 1);
  221.                       LoadSRAMCode(0, progAddr, fib.fib_Size >> 2);
  222.                     }
  223.                     if(config.sys_flags & 0x00000002)
  224.                     {
  225.                       Abort082(extio, TMS340Base, 1);
  226.                       Set082Regs(extio, TMS340Base, 1, CR_CONFIG, data, 1);
  227.                       LoadSRAMCode(1, progAddr, fib.fib_Size >> 2);
  228.                     }
  229.                     if(config.sys_flags & 0x00000004)
  230.                     {
  231.                       Abort082(extio, TMS340Base, 2);
  232.                       Set082Regs(extio, TMS340Base, 2, CR_CONFIG, data, 1);
  233.                       LoadSRAMCode(2, progAddr, fib.fib_Size >> 2);
  234.                     }
  235.                     if(config.sys_flags & 0x00000008)
  236.                     {
  237.                       Abort082(extio, TMS340Base, 3);
  238.                       Set082Regs(extio, TMS340Base, 3, CR_CONFIG, data, 1);
  239.                       LoadSRAMCode(3, progAddr, fib.fib_Size >> 2);
  240.                     }
  241.                   }
  242.                   else
  243.                   {
  244.                     printf("Error reading SRAM file.\n");
  245.                     data -= 64;
  246.                     gsp_free(data);
  247.                     prog -= 64;
  248.                     gsp_free(prog);
  249.                     CloseSAGE(&sageinfo);
  250.                     FreeSAGEList(sagelist);
  251.                     CloseLibrary(SAGEBase);
  252.                   }
  253.                 }
  254.                 else
  255.                 {
  256.                   printf("Unable to allocate working DRAM.\n");
  257.                   prog -= 64;
  258.                   gsp_free(prog);
  259.                   CloseSAGE(&sageinfo);
  260.                   FreeSAGEList(sagelist);
  261.                   CloseLibrary(SAGEBase);
  262.                 }
  263.               }
  264.               else
  265.               {
  266.                 printf("Unable to allocate enough DRAM for SRAM code.\n");
  267.                 CloseSAGE(&sageinfo);
  268.                 FreeSAGEList(sagelist);
  269.                 CloseLibrary(SAGEBase);
  270.               }
  271.               Close(handle);
  272.             }
  273.             else
  274.             {
  275.               printf("Unable to open %s.\n", SRAM_FILE);
  276.               CloseSAGE(&sageinfo);
  277.               FreeSAGEList(sagelist);
  278.               CloseLibrary(SAGEBase);
  279.             }
  280.           }
  281.           else
  282.           {
  283.             printf("No coprocessors found on your Vivid card.\n");
  284.             CloseSAGE(&sageinfo);
  285.             FreeSAGEList(sagelist);
  286.             CloseLibrary(SAGEBase);
  287.           }
  288.         }
  289.         else
  290.         {
  291.           printf("Unable to open extSRAM.library.\n");
  292.           CloseSAGE(&sageinfo);
  293.           FreeSAGEList(sagelist);
  294.           CloseLibrary(SAGEBase);
  295.         }
  296.       }
  297.       else
  298.       {
  299.         printf("Unable to load vivid.library and initialize board.\n");
  300.         FreeSAGEList(sagelist);
  301.         CloseLibrary(SAGEBase);
  302.       }
  303.     }
  304.     else
  305.     {
  306.       printf("SAGEList not found.\n");
  307.       CloseLibrary(SAGEBase);
  308.     }
  309.   }
  310.   else
  311.   {
  312.     printf("sage.library not found.\n");
  313.   }
  314.  
  315.   if(!(Screen = OpenScreenTags(NULL,
  316.                                SA_Width, 800,
  317.                                SA_Height, 600,
  318.                                SA_Depth, 8,
  319.                                SA_DisplayID, 0x00089024,
  320.                                TAG_END)))
  321.   {
  322.     Screen = OpenScreenTags(NULL,
  323.                             SA_AutoScroll, TRUE,
  324.                             SA_Width, 800,
  325.                             SA_Height, 600,
  326.                             SA_Depth, 4,
  327.                             SA_DisplayID, 0x00008004,
  328. //                            SA_Overscan, OSCAN_VIDEO,
  329.                             TAG_END);
  330.   }
  331.   
  332.   if(!Screen)
  333.   {
  334.     printf("Unable to open 800 x 600 screen.\n");
  335.   }
  336.   else
  337.   {
  338.     Window = OpenWindowTags(NULL,
  339.                             WA_CustomScreen, Screen,
  340.                             WA_Width, 800,
  341.                             WA_Height, 600,
  342.                             WA_Flags, WFLG_BACKDROP | WFLG_BORDERLESS | WFLG_ACTIVATE | WFLG_RMBTRAP,
  343.                             TAG_END);
  344.   }
  345.   
  346.   if(config.sys_flags & 0x0000000f)
  347.   {
  348.     printf("Testing Vivid 24 at 800 x 600.\n");
  349.     timer(clock1);
  350.     Mandel(extio, TMS340Base, HRES, VRES);
  351.     synchronize();
  352.   }
  353.   
  354.   timer(clock2);
  355.   
  356.   if(Screen)
  357.   {
  358.     printf("Testing Amiga at 800 x 600.\n");
  359.     ComputeFractal();
  360.     timer(clock3);
  361.   }
  362.   
  363.   
  364.   if(SAGEAlive)
  365.   {
  366.     if(Screen)
  367.     {
  368.       vividTime = clock2[0] - clock1[0];
  369.       amigaTime = clock3[0] - clock2[0];
  370.       printf("TIMES -> Amiga: %d seconds (%02d:%02d), Vivid 24: %d seconds (%02d:%02d).\n",
  371.           amigaTime, amigaTime / 60, amigaTime % 60,
  372.           vividTime, vividTime / 60, vividTime % 60);
  373.       printf("The Vivid was %d times as fast as the Amiga!\n",
  374.              amigaTime / vividTime);
  375.     }
  376.     else
  377.     {
  378.       vividTime = clock2[0] - clock1[0];
  379.       printf("TIME -> Vivid 24: %d seconds (%02d:%02d).\n",
  380.              vividTime, vividTime / 60, vividTime % 60);
  381.     }
  382.   }
  383.   else
  384.   {
  385.     amigaTime = clock3[0] - clock2[0];
  386.     printf("TIME -> Amiga: %d seconds (%02d:%02d).\n",
  387.            amigaTime, amigaTime / 60, amigaTime % 60);
  388.     printf("Compare: Vivid 24 with 1 copro:  15 seconds (00:15) = %d times your Amiga!\n", amigaTime / 15);
  389.     printf("         Vivid 24 with 2 copro:  7 seconds (00:07) = %d times your Amiga!\n", amigaTime / 8);
  390.     printf("         Vivid 24 with 4 copro:  4 seconds (00:04) = %d times your Amiga!\n", amigaTime / 4);
  391.   }
  392.   
  393.   if(Screen)
  394.   {
  395.     ScreenToBack(Screen);
  396.     printf("Press <Enter> to continue.\n");
  397.     getch();
  398.     if(Window)
  399.       CloseWindow(Window);
  400.     CloseScreen(Screen);
  401.   }
  402.   
  403.   if(SAGEAlive)
  404.   {
  405.     synchronize();
  406.     close_gsp_library(extio);
  407.     CloseSAGE(&sageinfo);
  408.     FreeSAGEList(sagelist);
  409.     CloseLibrary(SAGEBase);
  410.   }
  411. }
  412.